package com.suxin.thread.jmm;

/**
 * @author Tang
 * @classname Thread3
 * @description [ 可见性 ]
 * @date 2021/8/30 22:04
 */
public class Thread3 {

    private boolean flage = true;

    public static void main(String[] args) throws Exception{

        Thread3 thread3 = new Thread3();

        Thread thread1 = new Thread(() -> {
            while (thread3.flage) {
//                System.out.println("flage 运行中...");
            }
        }, "thread-1");
        thread1.start();

        Thread.sleep(300);

        Thread thread2 = new Thread(() -> {
            System.out.println("改变 flage 开始...");
            thread3.flage = false;
            System.out.println("改变 flage 结束...");
        });
        thread2.start();

        System.out.println("------------------" + thread3.flage);
    }


}